package com.leetcode.partition6;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

/**
 * @author `RKC`
 * @date 2021/11/27 16:41
 */
public class LC519随机翻转矩阵 {

    private static class Solution {
        private Set<Integer> set = new HashSet<>();
        private Random random = new Random();
        private int m;
        private int n;

        public Solution(int m, int n) {
            this.m = m;
            this.n = n;
        }

        public int[] flip() {
            int a = random.nextInt(m * n), b = a;
            while (a >= 0 && set.contains(a)) a--;
            while (b < m * n && set.contains(b)) b++;
            int c = a >= 0 && !set.contains(a) ? a : b;
            set.add(c);
            return new int[]{c / n, c % n};
        }

        public void reset() {
            set.clear();
        }
    }
}
